package com.mp.approvalreq.dao;

import com.mp.approvalreq.entity.*;
import com.mp.approvalreq.entity.GeneralRequest.GeneralRequest;
import com.mp.comment.entity.Comment;
import com.mp.user.entity.User;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 模板dao
 *
 * @author Administrator
 */
public interface TemplateDao {

	Template selectTemplateDetailById(Integer templateId) throws Throwable;
	/**
	 * 获取当前有效的所有方案
	 *
	 * @param companyId
	 * @return
	 * @throws Throwable
	 */
	List<Template> selectAllEffectiveTemplate(Integer companyId) throws Throwable;

	/**
	 * 批量修改模板审批流和抄送人
	 *
	 * @param templates
	 * @throws Throwable
	 */
	void updateTemplateFlowAndCc(List<Template> templates) throws Throwable;
	/**
	 * 根据id查询模板集合
	 *
	 * @param templateIds
	 * @return
	 * @throws Throwable
	 */
	Map<Integer, Template> selectTemplateByIds(String templateIds) throws Throwable;

	/**
	 * 获取模板的条件审批流
	 *
	 * @param templateId
	 * @return
	 * @throws SQLException
	 */
	List<ConditionFlow> selectConditionFlowList(Integer templateId) throws SQLException;

	/**
	 * 获取模板信息
	 *
	 * @param templateId
	 * @param companyId
	 * @return
	 * @throws SQLException
	 */
	Template getTemplate(Integer templateId, Integer companyId) throws SQLException;

	/**
	 * 获取模板组件集合关联字段
	 *
	 * @param templateIds
	 * @return
	 * @throws SQLException
	 */
	List<Template> getTemplateGroupJson(String templateIds) throws SQLException;

	/**
	 * 获取该模板的祖先模板的简单信息
	 *
	 * @param templateId
	 * @param companyId
	 * @return
	 * @throws SQLException
	 */
	Template getAncestorTemplateSimpleInfo(Integer templateId, Integer companyId) throws SQLException;

	/**
	 * 作废此模板
	 *
	 * @param templateId
	 * @param companyId
	 * @throws SQLException
	 */
	void disableTemplate(Integer templateId, Integer companyId) throws SQLException;


	/**
	 * 获取这些人在这些天申请过的所有模板
	 *
	 * @param list
	 * @param days
	 * @param userList
	 * @return
	 * @throws Throwable
	 */
	List<Integer> getUsedTemplateIdsInDaysByTemplateIdsAndUsers(List<Template> list, List<String> days, List<User> userList) throws Throwable;

	/**
	 * 获取这些天全公司申请的所有模板
	 *
	 * @param list
	 * @param days
	 * @return
	 * @throws Throwable
	 */
	List<Integer> getUsedTemplateIdsInDaysByTemplateIds(List<Template> list, List<String> days) throws Throwable;

	/**
	 * 获取本人所有身份在这些天这些模板中申请过审批的模板
	 *
	 * @param list
	 * @param days
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Integer> getUsedTemplateIdsInDaysByTemplateIdsAndUser(List<Template> list, List<String> days, User user) throws Throwable;

	/**
	 * 获取审批相关人群信息
	 *
	 * @param approvalIdList
	 * @return
	 * @throws Throwable
	 */
	List<Request> getAllPeopleOfApproval(List<Integer> approvalIdList) throws Throwable;

	/**
	 * 批量获取模板详情
	 *
	 * @param templateIdList
	 * @return
	 * @throws Throwable
	 */
	List<Template> getTemplateDetailByTemplateIdList(List<Integer> templateIdList) throws Throwable;

	/**
	 * 初始化我们公司的所有可用模板
	 *
	 * @param companyId
	 * @param defaultTemplates
	 * @throws Throwable
	 */
	void initMyCompanyTemplateList(Integer companyId, List<Template> defaultTemplates) throws Throwable;

	/**
	 * 获得可初始化的默认模板列表
	 *
	 * @return
	 * @throws Throwable
	 */
	List<Template> getDefaultTemplateToInit() throws Throwable;

	/**
	 * 获得我们公司的所有可用模板
	 *
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Template> getAllOfMyCompanyTemplate(User user) throws Throwable;

	/**
	 * 获得我们公司的所有可用模板
	 *
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Template> getTemplateFitToWholeCompanyRangeList(User user) throws Throwable;

    /**
	 * 获得模板详细
	 *
	 * @param template
	 * @return
	 * @throws Throwable
	 */
	Template getTemplateDetailWithoutVersion(Template template) throws Throwable;

	/**
	 * 获得模板详细
	 *
	 * @param templateId
	 * @return
	 * @throws SQLException
	 */
	Template getDefaultTemplateDetail(Integer templateId) throws SQLException;

	/**
	 * 根据审批查找模板详细
	 *
	 * @param request
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	Request getTemplateDetailByRequests(Request request, User user) throws Throwable;

	/**
	 * 公司修改默认模板生成新模板的子模板
	 *
	 * @param template
	 * @param user
	 * @param generation
	 * @throws Throwable
	 */
	void insertOriginTemplate(Template template, User user, int generation) throws Throwable;

	/**
	 * 删除模板
	 *
	 * @param template
	 * @param user
	 * @throws Throwable
	 */
	void deleteTemplate(Template template, User user) throws Throwable;

	/**
	 * 获得拒绝链的详细信息
	 *
	 * @param refuseChainIds
	 * @return
	 * @throws Throwable
	 */
	List<RefuseChain> getRefuseChainDetail(String refuseChainIds) throws Throwable;

	/**
	 * 根据祖先id获取最后一次使用的模板id
	 *
	 * @param request
	 * @return
	 * @throws Throwable
	 */
	Request getLatestTemplateByAncestorId(Request request) throws Throwable;

	/**
	 * 获得关联成本分析的所有模板以及父辈模板
	 *
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Template> selectCostAnalysisTemplates(User user) throws Throwable;

	/**
	 * 根据公司id获得关联成本分析的所有模板以及父辈模板
	 *
	 * @param request
	 * @return
	 * @throws Throwable
	 */
	List<Template> selectCostAnalysisTemplates(Request request) throws Throwable;

	/**
	 * 根据模板列表获得与之相关的所有模板
	 *
	 * @param list
	 * @return
	 * @throws Throwable
	 */
	List<Template> getTemplateFamilyByTemplates(List<Template> list) throws Throwable;

	/**
	 * 获得通过模板id获得审批
	 *
	 * @param templateIdList
	 * @param request
	 * @return
	 * @throws Throwable
	 */
	List<Request> getRequestByTemplates(List<Template> templateIdList, Request request) throws Throwable;

	/**
	 * 获得通过模板id获得审批
	 *
	 * @param templateIdList
	 * @param request
	 * @return
	 * @throws Throwable
	 */
	List<Request> getRequestByTemplatesWithSearchRangeAndCurrentMonths(List<Template> templateIdList, Request request) throws Throwable;

	/**
	 * 插入条件审批流
	 *
	 * @param template
	 * @param user
	 * @throws Throwable
	 */
	void insertConditionRequestFlow(Template template, User user) throws Throwable;

	/**
	 * 获得用过的公司模板
	 *
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Template> getTemplateUsed(User user) throws Throwable;

	/**
	 * 获取模板的一系列祖先模板
	 *
	 * @param template
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Template> getTemplateFamilyByTemplates(Template template, User user) throws Throwable;

	/**
	 * 获取评论
	 *
	 * @param request
	 * @param user
	 * @return List<Comment>
	 * @throws Throwable
	 */
	List<Comment> getCommentMessage(Request request, User user) throws Throwable;

	/**
	 * 获取通用审批流设置
	 *
	 * @param request
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	GeneralRequest getCompanyGeneralFlowSettings(GeneralRequest request, User user) throws Throwable;

	/**
	 * 自定义普通模板
	 *
	 * @param request
	 * @param user
	 * @throws Throwable
     * @return
	 */
	int saveGeneralRequestFlow(GeneralRequest request, User user) throws Throwable;

	/**
	 * 自定义普通模板条件审批流
	 *
	 * @param request
	 * @param user
	 * @throws Throwable
	 */
	void saveGeneralRequestConditionFlow(GeneralRequest request, User user) throws Throwable;

	/**
	 * 作废自定义普通模板条件审批流
	 *
	 * @param request
	 * @param user
	 * @throws Throwable
	 */
	void disableGeneralRequestConditionFlow(GeneralRequest request, User user) throws Throwable;


	/**
	 * 获得某人某段时间的审批成本
	 *
	 * @param templateIdList
	 * @param request
	 * @return
	 * @throws Throwable
	 */
	List<Request> siftingRequestRelatedToCostAnalysis(List<Template> templateIdList, List<Request> request) throws Throwable;

	/**
	 * 获得关联成本分析的所有模板以及父辈模板
	 *
	 * @param companies
	 * @return
	 * @throws Throwable
	 */
	List<Template> getRelatedToCostAnalysisTemplateListInTheseCompanies(List<Integer> companies) throws Throwable;


	/**
	 * 获得我们公司的所有可用模板
	 *
	 * @param user
	 * @return
	 * @throws Throwable
	 */
	List<Template> getCompanyGeneralTemplateList(User user) throws Throwable;
	/**
	 * 根据审批id获取模版（按祖先id分组）
	 *
	 * @param requestIds
	 * @return
	 */
	List<Template> selectLastTemplateByRequestIds(String requestIds) throws Throwable;

	List<Template> selectTemplateByRequestIds(String requestIds) throws Throwable;

	/**
	 * 根据审批id查询模版详情
	 *
	 * @param requestId
	 * @return
	 * @throws Throwable
	 */
	Template selectTemplateByRequestId(Integer requestId) throws Throwable;

	/**
	 * 根据祖先ID查询所有模版
	 *
	 * @param ancestorId
	 * @return
	 * @throws Throwable
	 */
    List<Template> selectTemplatesByAncestorId(Integer ancestorId) throws Throwable;

}
